package com.mm.ai.domain.po;

import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import lombok.Data;

/**
 * @BelongsProject: 8.mindmap
 * @BelongsPackage: com.mm.ai.domain.po
 * @Author : 游在海里的鱼
 * @CreateTime : 2024-05-17  20:35
 * @Version : 1.0
 * @ClassName : TODO
 * @Description : TODO
 */
@Data
public class Gpt3Response {
    /* chatGPT3.5的响应
    {
        "id": "chatcmpl-9PqxK9QVVZsiA2HwnLVHmpzIjWvTJ",
        "object": "chat.completion",
        "created": 1715948790,
        "model": "gpt-3.5-turbo-0125",
        "choices": [ { "index": 0, "message": { "role": "assistant", "content": "你好！有什么可以帮助你的吗？" },"logprobs": null, "finish_reason": "stop" } ],
        "usage": { "prompt_tokens": 9, "completion_tokens": 17, "total_tokens": 26 },
        "system_fingerprint": null
    }
    */
   private String id;
   private String object;
   private String created;
   private String choices;
   private String usage;
   private String system_fingerprint;

   public String getContent(){
      if(this.choices == null){
         return null;
      }
      JSONArray jsonArray = new JSONArray(this.choices);
      JSONObject jsonObject = jsonArray.getJSONObject(0);
      JSONObject messageObj = jsonObject.getJSONObject("message");
      return messageObj.getStr("content");
   }
}
